Example Program
Exact Searching
Exact string matching.
1#include <iostream>
2#include <seqan/find.h>
3
4using namespace seqan;
5using namespace std;
6
This function prints the positions all occurrences of needle within haystack. It uses the Algorithm specified by TAlgorithm that is passed as Specialization to Pattern.
7template <typename TAlgorithm>
8void printAllOccs(String<char>& haystack, 
9                  String<char>& needle)
10{
11    Finder<String<char> > finder(haystack);
12    Pattern<String<char>, TAlgorithm> pattern(needle);
13    while (find(finder, pattern)) 
14    {
15        std::cout << position(finder) << ", ";
16    }
17    std::cout << std::endl;
18}
19
The main function calls printAllOccs for different exact string matching algorithms.
20int main() 
21{
22    String<char> haystack = "send more money!";
23    String<char> needle = "mo";
24
25    printAllOccs<Horspool>(haystack, needle);
26    printAllOccs<BomAlgo> (haystack, needle);
27    printAllOccs<BndmAlgo>(haystack, needle);
28    printAllOccs<ShiftAnd>(haystack, needle);
29    printAllOccs<ShiftOr> (haystack, needle);
30
31    return 0;
32}
33
See Also
SeqAn - Sequence Analysis Library - www.seqan.de